1c97358735a66488d11be010fb0b928a60e7332c,src/main/java/act/view/RenderAny.java,RenderAny,apply,#ActionContext#,39

Before Change


    }

    // TODO: Allow plugin to support rendering pdf, xls or other binary types
    public void apply(ActionContext context) {
        H.Format fmt = context.accept();
        if (fmt == UNKNOWN) {
            throw E.unsupport("Unknown accept content type");
        }
        if (JSON == fmt) {
            List<String> varNames = context.__appRenderArgNames();
            Map<String, Object> map = C.newMap();
            if (null != varNames && !varNames.isEmpty()) {
                for (String name : varNames) {
                    map.put(name, context.renderArg(name));
                }
            }
            new RenderJSON(map).apply(context.req(), context.resp());
            return;
        } else if (XML == fmt) {
            List<String> varNames = context.__appRenderArgNames();
            Map<String, Object> map = C.newMap();
            if (null != varNames && !varNames.isEmpty()) {
                for (String name : varNames) {
                    map.put(name, context.renderArg(name));
                }
            }
            new FilteredRenderXML(map, null, context).apply(context.req(), context.resp());
            return;
        } else if (HTML == fmt || TXT == fmt || CSV == fmt) {
            RenderTemplate.get().apply(context);
            return;
        } else if (PDF == fmt || XLS == fmt || XLSX == fmt || DOC == fmt || DOCX == fmt) {
            List<String> varNames = context.__appRenderArgNames();
            if (null != varNames && !varNames.isEmpty()) {
                Object firstVar = context.renderArg(varNames.get(0));
                String action = S.str(context.actionPath()).afterLast(".").toString();
                if (firstVar instanceof File) {
                    File file = (File) firstVar;
                    new RenderBinary(file, action).apply(context.req(), context.resp());
                } else if (firstVar instanceof InputStream) {
                    InputStream is = (InputStream)firstVar;
                    new RenderBinary(is, action).apply(context.req(), context.resp());
                } else if (firstVar instanceof ISObject) {
                    ISObject sobj = (ISObject) firstVar;
                    new RenderBinary(sobj.asInputStream(), action).apply(context.req(), context.resp());

After Change


            }
            result = new FilteredRenderXML(map, null, context);
        } else if (HTML == fmt || TXT == fmt || CSV == fmt) {
            RenderTemplate.get(context.successStatus()).apply(context);
            return;
        } else if (PDF == fmt || XLS == fmt || XLSX == fmt || DOC == fmt || DOCX == fmt) {
            List<String> varNames = context.__appRenderArgNames();
            if (null != varNames && !varNames.isEmpty()) {
                Object firstVar = context.renderArg(varNames.get(0));
                String action = S.str(context.actionPath()).afterLast(".").toString();
                if (firstVar instanceof File) {
                    File file = (File) firstVar;
                    result = new RenderBinary(file, action);
                } else if (firstVar instanceof InputStream) {
                    InputStream is = (InputStream) firstVar;
                    result = new RenderBinary(is, action);
                } else if (firstVar instanceof ISObject) {
                    ISObject sobj = (ISObject) firstVar;
                    result = new RenderBinary(sobj.asInputStream(), action);
                }
                if (null == result) {
                    throw E.unsupport("Unknown render arg type [%s] for binary response", firstVar.getClass());
                }
            } else {
                throw E.unexpected("No render arg found for binary response");
            }
        }
        if (null != result) {
            result.status(context.successStatus()).apply(context.req(), context.resp());
        } else {
            throw E.unexpected("Unknown accept content type: %s", fmt.contentType());
        }